import Vue from "vue";
import Vuex from "../../vuex";
Vue.use(Vuex);
import a from "./a";
import b from "./b";
function log() {
  return function(store) {
    let data = localStorage.getItem("VUEX:STATE");
    if (data) {
      store.replaceState(JSON.parse(data));
    }
    store.subscribe((mutation, state) => {
      localStorage.setItem("VUEX:STATE", JSON.stringify(state));
    });
  };
}
export default new Vuex.Store({
  plugins: [log()],
  state: {
    age: 18,
    navIdx: 0,
  },
  getters: {
    myAge(state) {
      return state.age + 20;
    },
  },
  mutations: {
    changeAge(state, payload) {
      state.age += payload;
    },
    changeIdx(state, payload) {
      state.navIdx = payload;
    },
  },
  actions: {
    changeAgeSet({ commit }, payload) {
      setTimeout(() => {
        commit("changeAge", payload);
      }, 1000);
    },
  },
  modules: {
    a,
    b,
  },
});
